<template>
	<view class="">
		<!-- <statusbar></statusbar>
		<view class="header" :style="{paddingRight:paddingright==0?'32rpx':paddingright}">
			<view class="left">
				<u-search placeholder="搜索你需要购买的商品" v-model="keyword" :showAction='false'></u-search>
			</view>
			<view class="right">
				<image class="scan_icon" src="/static/img/home/scan.png" mode=""></image>
			</view>
		</view> -->
		<u-navbar>
			<view class="u-nav-slot" slot="left" :style="{width:`calc(750rpx - 52rpx - ${paddingright})`}">
				<view class="left">
					<u-search placeholder="搜索你需要购买的商品" v-model="keyword" :disabled="true" @click='clickto("/pages/searchpage/searchpage")' :showAction='false'></u-search>
				</view>
			</view>
		</u-navbar>
		<view class="con" :style="{paddingTop:marginTop+'px'}">
			<view class="left_box">
				<scroll-view scroll-y="true" class="scy">

					<view class="tab_item" :class="index==curi?'active':''" @click="clicktab(item.id,index)"
						v-for="(item,index) in tablist" :key="index">
						<view class="item_line_box" v-if="index==curi">
							<view class="item_line">

							</view>
						</view>
						{{item.name}}
					</view>
				</scroll-view>
			</view>
			<view class="right_box">
				<view class=""  style="border-radius: 20rpx;overflow: hidden;background-color: #fff;">
					<view class="right_title">
						{{tablist[curi].name||''}}
					</view>
					<scroll-view scroll-y="true" class="scy scr" style="overflow: hidden;">
						<!-- background-color: #fff;border-radius: 20rpx; -->
						<view class="" style="background-color: #fff;border-radius: 0 0 20rpx 20rpx;">

							<view class="product">
								<view class="product_item" @click="clickto(`/pages/product/prodetail?id=${item.id}&title=商品详情`)" v-for="(item,index) in prolist" :key="index">
									<image class="item_icon" :src="item.img" mode="aspectFill"></image>
									<text class="item_text">{{item.name}}</text>
								</view>
							</view>
						</view>

					</scroll-view>
				</view>

			</view>
		</view>
	</view>

</template>

<script>
	import {
		homeData
	} from '@/api/home.js'
	import {
		getProductByCateGory
	} from '@/api/product.js'
	let menuButtonInfo = uni.getMenuButtonBoundingClientRect()
	export default {
		data() {
			return {
				paddingright: 0,
				keyword: '',
				tablist: [],
				curi: 0,
				prolist: [],
				marginTop: 0,
				cateGoryId: ''
			};
		},
		onLoad() {
			// #ifdef MP
			this.paddingright = `calc(750rpx - ${menuButtonInfo.left}px + 32rpx)`
			// console.log(this.paddingright)
			// #endif
			this.marginTop = 44 + uni.getStorageSync('statusBarHeight')
			homeData().then(res => {
				this.tablist = res.data.data.category
				this.getProductCategory(this.tablist[0].id)
			})

		},
		methods: {
			async getProductCategory(id) {
				const res = await getProductByCateGory({
					category_id: id
				})
				this.prolist = res.data.data
				this.prolist.map(t => {
					t.img = this.$BASE_URL + t.images.split(',')[0]
					
				})
				
			},
			clicktab(id,index){
				this.curi=index
				this.getProductCategory(id)
			},
			clickto(url){
				uni.navigateTo({
					url
				})
			}
		}
	}
</script>

<style lang="less">
	page {
		background-color: #F2F2F2;
		height: 100%;
	}

	.con {
		display: flex;
		height: 100%;
	}

	.left_box {
		width: 25%;
	}

	.right_box {
		width: 75%;
		padding: 35rpx;
		border-radius: 20rpx;
		overflow: hidden;
	}

	.scy {
		height: calc(100vh - var(--status-bar-height) - 125rpx - 126rpx);
		/* #ifdef MP */
		height: calc(100vh - var(--status-bar-height) - 125rpx);
		/* #endif */
	}

	.right_title {
		padding: 0 0 0 40rpx;
		font-size: 32rpx;
		font-weight: bold;
		color: #292929;
		line-height: 88rpx;
		background-color: #fff;
	}

	.tab_item {
		position: relative;
		color: #474747;
		font-size: 26rpx;
		padding: 40rpx 0;
		text-align: center;

		.item_line_box {
			position: absolute;
			display: flex;
			align-items: center;
			height: 100%;
			top: 0;
		}

		.item_line {
			width: 7rpx;
			height: 32rpx;
			background: #FF6101;
		}
	}

	.active {
		color: #333;
		font-size: 32rpx;
		font-weight: bold;
	}

	.con_box {
		padding: 18rpx 10rpx;

		.img {
			width: 100%;
		}
	}

	.product {
		display: flex;
		align-items: center;
		// justify-content: space-between;
		flex-wrap: wrap;
		.product_item {
			display: flex;
			flex-direction: column;
			align-items: center;
			width: 33.3333%;
			padding-bottom: 40rpx;
			.item_icon {
				width: 110rpx;
				height: 110rpx;
				border-radius: 10rpx;
			}

			.item_text {
				width: 110rpx;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
				text-align: center;
				margin-top: 20rpx;
				font-size: 24rpx;
				color: #5D5D5D;
			}
		}
	}

	.scr {

		height: calc(100vh - var(--status-bar-height) - 125rpx - 126rpx - 70rpx - 88rpx);
		/* #ifdef MP */
		height: calc(100vh - var(--status-bar-height) - 125rpx - 70rpx - 88rpx);
		/* #endif */
	}

	.header {
		// height: 158rpx;
		background-color: #fff;
		padding: 0 39rpx 0 30rpx;
		height: 125rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;

		.left {
			color: #333333;
			font-size: 36rpx;
			flex: 1;
		}

		.right {
			display: flex;
			align-items: center;
			margin-left: 20rpx;

			.del_icon {
				width: 39rpx;
				height: 39rpx;
			}

			.sousuo_icon {
				width: 43rpx;
				height: 46rpx;
				margin-left: 35rpx;
			}
		}
	}

	.scan_icon {
		width: 40rpx;
		height: 40rpx;
	}

	.u-nav-slot {
		display: flex;
		align-items: center;
		width: calc(750rpx - 52rpx);

		.left {
			width: 100%;
		}
	}
</style>
